<template>
  <back-dialog-base
    :title="title"
    :visible="visibleAnalysis"
    width="410px"
    @onCommit="handleSubmit"
  >
    <template #content>
      <div class="content-wrap">
        <el-form ref="formRef" :model="form" :rules="rules" label-width="60px">
          <el-form-item style="width: 100%">
            <span class="listFont"
              >是否确定提交
              <span v-for="(item, index) in props.rowListData" :key="item.id">
                {{
                  rowListData[index]
                    ? rowListData[index].pipelineApplyForm.projectName
                    : ''
                }}&nbsp;</span
              >工程入廊申请</span
            >
          </el-form-item>
        </el-form>
      </div>
    </template>
  </back-dialog-base>
</template>

<script setup>
import { reactive, defineProps, ref, defineEmits, watch } from 'vue'
import BackDialogBase from '@/components/BackDialogBase'
import { message } from '@/utils/message'
import { savePipeaduit } from '@/api/pipeline'
const commitArr = ref([])
const props = defineProps({
  title: {
    type: String,
    default: ''
  },
  visibleAnalysis: {
    type: Boolean,
    default: false
  },
  rowListData: {
    type: Object,
    default: () => {}
  }
})

const emits = defineEmits(['onReload'])
const formRef = ref(null)
const form = reactive({
  name: ''
})
// const rules = reactive({
//   analyzeResult: [
//     { required: true, message: '请选择分析结果', trigger: 'change' }
//   ],
//   analyzeUser: [
//     {
//       required: true,
//       message: '请选择接收人',
//       trigger: 'change'
//     }
//   ]
// })

const handleSubmit = () => {
  console.log(!!props.rowListData.length)
  if (props.rowListData.length === undefined) {
    message({ type: 'warning', message: '请至少选择一条信息！' })
  } else {
    props.rowListData.forEach((item) => {
      commitArr.value.push(item.pipelineApplyForm.id)
    })
    save(commitArr.value)
  }
}

const save = async (data) => {
  await savePipeaduit(data).then(() => {
    message({ type: 'success', message: '保存成功!' })
    emits('onReload')
  })
}

// const handleSubmit = () => {
//   formRef.value.validate((val) => {
//     if (val) {
//       if (formInline.analyzeResult === '真警') {
//         formInline.dealState = formInline.analyzeResult === '真警' ? 1 : ''
//         userwaring(Object.assign({ ...props.rowData }, formInline))
//       } else {
//         delete formInline.analyzeUser
//         formInline.dealState = formInline.analyzeResult === '误报' ? 2 : ''
//         userwaring(Object.assign({ ...props.rowData }, formInline))
//       }
//     } else {
//       console.log('提交失败')
//       return false
//     }
//   })
// }
// const userwaring = async (val) => {
//   await userAnalysis(val).then(() => {
//     ElMessage({
//       message: '操作成功！',
//       type: 'success'
//     })
//     emits('onReload')
//   })
// }
// const User = async () => {
//   options.value = await user()
// }
// User()
// const clear = () => {
//   const form = unref(formRef)
//   form.resetFields()
//   clearformInline()
// }
// const clearformInline = () => {
//   formInline.analyzeResult = '真警'
//   formInline.analyzeSuggest = ''
//   formInline.analyzeUser = ''
// }

// const clearForm = () => {
//   if (!formRef.value) return
//   formRef.value.resetFields()
//   form.value = {
//     name: '',
//     number: '',
//     code: ''
//   }
// }
</script>

<style lang="scss" scoped>
.font {
  font-size: 16px;
  font-family: Source Han Sans CN;
  color: #333333;
}
:deep(.el-date-editor.el-input, .el-date-editor.el-input__inner) {
  width: 100%;
}
.content-wrap {
  width: 100%;
  height: 100%;
  display: flex;
  font-size: 13px;
  .right-form {
    span {
      width: 26px;
      height: 15px;
    }
  }
}
.el-input {
  width: 150px;
}
.el-select {
  width: 150px;
}
</style>
